package io.xiyou.user.controller;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @ClassName：RocketController
 * @Author：西柚
 * @Date：2021/11/5 4:13 下午
 * @Versiion：1.0
 */
@RestController
public class RocketSendMessageController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    // 延时消息，RocketMQ支持这几个级别的延时消息，自定义需要修改broker配置文件
    // 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
    @GetMapping("/rocket/delayMsg/send")
    public String rocketDelayMsgSend() {
        LocalDateTime currentDateTime = LocalDateTime.now();
        rocketMQTemplate.syncSend("rocket-topic-2:tag-2", MessageBuilder.withPayload(currentDateTime.toString()).build(), 2000, 3);
        return currentDateTime.toString();
    }
}
